use std::fmt::format;
use std::thread;
use std::time::Duration;
use concurrency::Metrics;

fn main() {
    let  m1 = Metrics::new();

    for idx in 0..2 {
        worker(idx,m1.clone());
    }
    for idx in 0..2 {
        request(idx,m1.clone());
    }
    loop {
        thread::sleep(Duration::from_secs(1));
        println!("{:?}",m1.snapshot());
    }

}

 fn worker(idx:usize,mut metrics: Metrics) {
   thread::spawn(move || {
        loop {
            thread::sleep(Duration::from_secs(1));
            metrics.inc(format!("work.key {}",idx));
        }

   });
}

fn request(idx:usize,mut metrics: Metrics) {
    thread::spawn(move || {
        loop {
            thread::sleep(Duration::from_secs(1));
            metrics.inc(format!("request.key {}",idx));
        }

    });
}